﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EncuentraloSilverlight.Web.Models;
using System.Data.Linq;

namespace EncuentraloSilverlight.Web.Models
{

    public class AddressRepository
    {
        private EncuentraloDataBaseModelDataContext db;

        public AddressRepository()
        {
            db = new EncuentraloDataBaseModelDataContext();
            DataLoadOptions options = new DataLoadOptions();
            options.LoadWith<Address>(k => k.Seller);
            options.LoadWith<Address>(k => k.User);
            db.LoadOptions = options;
        }

        public IQueryable<Address> FindAllAddress()
        {
            return db.Addresses;
        }

        public void Add(Address address)
        {
            db.Addresses.InsertOnSubmit(address);
            Save();
        }

        public void Delete(Address address)
        {
            db.Addresses.DeleteOnSubmit(address);
            Save();
        }

        private void Save()
        {
            db.SubmitChanges();
        }

    }
}